﻿Imports System.Threading
Public Class cls_whisframework

    Dim Mysql As New ClsSQLhelper
    Public Shared Function Chk_Permission(ByVal int_permission As Integer) As Boolean
        Chk_Permission = False
        Try
            Dim Strsql As String = ""
            Dim Mysql As New ClsSQLhelper
            Dim DS As New DataSet

            Strsql = "Select * from grouppermission where groupid = " & My.Settings.CurrentuserGroup & " and  permissionid = " & int_permission & " and siteid = " & My.Settings.CurrentSite
            DS = Mysql.GetMYSQLDataset(Strsql, "DS_grouppermission", "grouppermission")
            If DS.Tables(0).Rows.Count = 0 Then Exit Function
            Chk_Permission = True

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Function : Chk_Permission")
        End Try

    End Function
    Public Shared Function Get_SiteItemInfo(ByVal MySiteItemnumber As String) As String
        Dim DS_Item As New DataSet
        Dim Strsql As String = ""
        Dim Mysql As New ClsSQLhelper
        Strsql = "SELECT itemcode,concat (item.itemname, '  (' ,itemunitofmeasure.unitofmeasure,' ) ') as items from item"
        Strsql = Strsql & " left join siteitemunit  on  item.itemnumber = siteitemunit.itemid "
        Strsql = Strsql & " left join itemunitofmeasure on siteitemunit.unitid= itemunitofmeasure.unitofmeasureid"
        Strsql = Strsql & " where itemcode = '" & MySiteItemnumber & "' order by itemname"
        DS_Item = Mysql.GetMYSQLDataset(Strsql, "DSItem", "item")
        Return DS_Item.Tables(0).Rows(0).Item("items").ToString()

    End Function
    Public Shared Function Load_CboOrderStatus(ByVal MyCombobox As ComboBox)
        Dim Strsql As String = ""
        Dim Mysql As New ClsSQLhelper
        Dim DS_OrderStatus As New DataSet
        Strsql = "Select * from orderstatus where active = 1"
        DS_OrderStatus = Mysql.GetMYSQLDataset(Strsql, "DSSite", "Site")
        With MyCombobox
            .DataSource = DS_OrderStatus.Tables(0)
            .DisplayMember = "orderstatus"
            .ValueMember = "orderstatusid"
            .SelectionStart = 0
        End With
        DS_OrderStatus.Dispose()

    End Function
    Public Shared Sub KeepSQLLog(ByVal Strsql As String)
        Dim DSWhis As New DSWHIS
        Dim myPackagesRows As DataRow
        myPackagesRows = DSWhis.Tables("sqllog").NewRow
        myPackagesRows(0) = Now
        myPackagesRows(1) = Strsql
        DSWhis.Tables("sqllog").Rows.Add(myPackagesRows)
    End Sub

    ReadOnly Property Get_DTSite() As DataTable
        Get
            Get_DTSite = Mysql.GetMYSQLDataTable("Select * from site where active = 1 order by site", "site")
        End Get
    End Property
    ReadOnly Property Get_DTOrderstatus() As DataTable
        Get
            Get_DTOrderstatus = Mysql.GetMYSQLDataTable("Select * from orderstatus where active = 1", "orderstatus")
        End Get
    End Property
    ReadOnly Property Get_CurrentUserfullname() As String
        Get
            Dim Strsql As String
            Strsql = "Select user_name from user where user = '" & My.Settings.Currentuser & "'"
            Get_CurrentUserfullname = Mysql.MySQLExecuteScalar(Strsql)

        End Get
    End Property
    ReadOnly Property Get_CurrentYearbudget(ByVal ThaiFormat As Boolean) As String
        Get
            Dim EngYear As Integer
            Dim ThaiYear As Integer
            Select Case Thread.CurrentThread.CurrentCulture.ToString
                Case "en-US"
                    If Month(Now) < 10 Then
                        EngYear = Year(Now)
                    Else
                        EngYear = Year(Now) + 1
                    End If
                    ThaiYear = EngYear + 543
                    Select Case ThaiFormat
                        Case True
                            Return ThaiYear
                        Case False
                            Return EngYear
                    End Select
                Case "th-TH"
                    If Month(Now) < 10 Then
                        ThaiYear = Year(Now)
                    Else
                        ThaiYear = Year(Now) + 1
                    End If
                    EngYear = ThaiYear - 543
                    Select Case ThaiFormat
                        Case True
                            Return ThaiYear
                        Case False
                            Return EngYear
                    End Select
            End Select
        End Get
    End Property


End Class
